package utils.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.myapplication.R;

import java.util.List;

import entity.AboutRecomEntity;
import utils.texttools.StringUtil;
import volley.VolleySingleton;

/**
 * Created by dllo on 15/12/5.
 */
public class RecomendaboutAdpter extends BaseAdapter {
    private List<AboutRecomEntity.AlbumsEntity> datas;

    public void addData(List<AboutRecomEntity.AlbumsEntity> datas){
        this.datas = datas;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return datas!=null && datas.size()>0 ? datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (datas!=null&&datas.size()>0){
            ViewHolder viewHolder = null;
            if (convertView==null){
                viewHolder = new ViewHolder();
                LayoutInflater inflater = LayoutInflater.from(parent.getContext());
                convertView=inflater.inflate(R.layout.about_item,null);
                viewHolder.aboutTitleIv= (NetworkImageView) convertView.findViewById(R.id.aboutTitleIv);
                viewHolder.aboutContent= (TextView) convertView.findViewById(R.id.aboutContent);
                viewHolder.aboutTitle = (TextView) convertView.findViewById(R.id.aboutTitle);
                viewHolder.aboutTracks= (TextView) convertView.findViewById(R.id.aboutTracks);
                viewHolder.aboutPlayNum= (TextView) convertView.findViewById(R.id.aboutPlayNum);
                convertView.setTag(viewHolder);
            }
            else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            VolleySingleton.getInstance().getBitmap(datas.get(position).getCoverMiddle(),viewHolder.aboutTitleIv);
            viewHolder.aboutTitle.setText(datas.get(position).getTitle());
            viewHolder.aboutTracks.setText(datas.get(position).getTracks()+"集");
            viewHolder.aboutContent.setText(datas.get(position).getIntro());
            viewHolder.aboutPlayNum.setText(StringUtil.longToWan(datas.get(position).getPlaysCounts()));
        }

        return convertView;
    }
    class  ViewHolder{
        private TextView aboutTracks,aboutPlayNum,aboutContent,aboutTitle;
        private NetworkImageView aboutTitleIv;
    }
}
